package org.execute.tool.文件处理;

import java.io.*;
import java.util.ArrayList;

/**
 * 读取文件生成数组
 */
public class ReadTheFileToGenerateAnArray {
    /**
     * 行替换
     * @param filePath
     */
    public static ArrayList<String> readTheFileToGenerateAnArray(String filePath) {
        ArrayList<String> strings = new ArrayList<>();
        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
            String line;
            while ((line = reader.readLine()) != null) {
                // 去除行尾的换行符
                line = line.trim();
            // 添加到数组中
                strings.add(line);

            }
        } catch (IOException e) {
            System.err.println("处理文件时发生错误：" + e.getMessage());
        }
        return strings;
    }

    public static void main(String[] args) {

        // 处理文件
        ArrayList<String> strings = readTheFileToGenerateAnArray("E:\\文件数组.txt");
        strings.forEach(System.out::println);
    }

}
